package com.hdoit.ares.web.acc.apis;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.hdoit.ares.logical.acc.model.AccountInfo;
import com.hdoit.ares.logical.acc.model.GoldenBeanInfo;
import com.hdoit.ares.logical.acc.model.IncomeInfo;
import com.hdoit.ares.logical.acc.service.IAccountInfoService;
import com.hdoit.ares.logical.acc.service.IGoldenBeanInfoService;
import com.hdoit.ares.logical.acc.service.IIncomeInfoService;
import com.tennetcn.component.webapi.BaseApi;
import com.tennetcn.component.webapi.ResponseModel;

@Controller
@RequestMapping(value="/api/v1/MyWealth/",method = {RequestMethod.GET,RequestMethod.POST},produces="application/json;charset=utf-8")
@Api(value="/api/v1/MyWealth/")
@CrossOrigin(origins = "*",maxAge = 3600)
public class MyWealthAresApi extends BaseApi{

	private IAccountInfoService accountInfoService;	
	public IAccountInfoService getAccountInfoService() {
		return accountInfoService;
	}
	@Resource
	public void setAccountInfoService(IAccountInfoService accountInfoService) {
		this.accountInfoService = accountInfoService;
	}

	private IGoldenBeanInfoService goldenBeanInfoService;
	public IGoldenBeanInfoService getGoldenBeanInfoService() {
		return goldenBeanInfoService;
	}
	@Resource
	public void setGoldenBeanInfoService(
			IGoldenBeanInfoService goldenBeanInfoService) {
		this.goldenBeanInfoService = goldenBeanInfoService;
	}

	private IIncomeInfoService incomeInfoService;	
	public IIncomeInfoService getIncomeInfoService() {
		return incomeInfoService;
	}
	@Resource
	public void setIncomeInfoService(IIncomeInfoService incomeInfoService) {
		this.incomeInfoService = incomeInfoService;
	}

	private final String myWhealthApi="myWhealth";
	
	@ResponseBody
	@RequestMapping(value= myWhealthApi)
	@ApiOperation(notes= myWhealthApi,httpMethod="POST",value="我的财富页面")
	public String myWhealth() {
	
		ResponseModel rm = new ResponseModel();
		String custId = getLoginId();
	
		AccountInfo accountInfo = accountInfoService.queryModelByCustomerId(custId);
		if(accountInfo==null){
			rm.setMessage("获取账户信息错误");
			return rm.toJson();
		}else{
			rm.put("accountInfo", accountInfo);
			rm.setMessage("ok");
		}

		GoldenBeanInfo goldenBeanInfo = goldenBeanInfoService.queryModelByCustomerId(custId);
		if(goldenBeanInfo==null){
			rm.setMessage("获取金豆信息错误");
			return rm.toJson();
		}else{
			rm.put("goldenBeanInfo", goldenBeanInfo);
			rm.setMessage("ok");
		}

		IncomeInfo incomeInfo = incomeInfoService.queryIncomeInfo(custId);
		if(incomeInfo==null){
			rm.setMessage("获取奖金信息错误");
			return rm.toJson();
		}else{
			rm.put("incomeInfo", incomeInfo);
			rm.setMessage("ok");
		}
		
		return rm.toJson();
	}
	
}
